﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace POC
{
    public partial class Form2 : Form
    {
        
        public Form2()
        {
            InitializeComponent();
            
            if (Globals.Create)
            {
                button1.Text = "Create Entry";
                FirstNametxt.Text = "";
                LastNametxt.Text = "";
                Emailtxt.Text = "";
                this.Text = "Create Entry";
            }
            else
            {
                button1.Text = "Update Entry";
                FirstNametxt.Text = Globals.lastClicked.FirstName;
                LastNametxt.Text = Globals.lastClicked.LastName;
                Emailtxt.Text = Globals.lastClicked.Email;
                this.Text = "Update Entry";
            }
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            if (button1.Text == "Create Entry")
            {
                AddressEntryDAO.Create(new AddressEntry(FirstNametxt.Text, LastNametxt.Text, Emailtxt.Text));
            }
            else
            {
                AddressEntryDAO.Update(new AddressEntry(FirstNametxt.Text, LastNametxt.Text, Emailtxt.Text));
            }
            this.Close();
        }

    }
}
